import os
import sys

from flask import Flask

from config.setting import SERVER_PORT
from router.user import user
from router.food import food
from router.blog import blog
from router.comment import comment
from router.dining_hall import hall
from flask_cors import *

BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, BASE_PATH)  # 将项目根路径临时加入环境变量，程序退出后失效


app = Flask(__name__)
CORS(app, resource=r'/*')

app.register_blueprint(user)
app.register_blueprint(food)
app.register_blueprint(hall)
app.register_blueprint(blog)
app.register_blueprint(comment)
app.config["JSON_AS_ASCII"] = False  # jsonify返回的中文正常显示


@app.before_request
def before_request_a():
    print('前置条件')


@app.after_request
def before_request_b(response):
    print('后置条件')
    return response


if __name__ == '__main__':
    # host为主机ip地址，port指定访问端口号，debug=True设置调试模式打开
    app.run(host="0.0.0.0", port=SERVER_PORT, debug=True)

